import { request } from '../request'
import type {
    Order,
    CreateOrderRequest,
    PageRequest,
    PageResponse
} from '@/types'

// 创建订单
export const createOrder = (data: CreateOrderRequest): Promise<number> => {
    return request.post('/api/order-service/api/order/create', data)
}

// 获取订单详情
export const getOrderDetail = (orderId: number): Promise<Order> => {
    return request.get(`/api/order-service/api/order/${orderId}`)
}

// 获取用户订单列表
export const getUserOrders = (userId: number): Promise<Order[]> => {
    return request.get(`/api/order-service/api/order/user/${userId}`)
}

// 取消订单
export const cancelOrder = (orderId: number): Promise<void> => {
    return request.post(`/api/order-service/api/order/${orderId}/cancel`)
}

// 获取订单状态日志
export const getOrderStatusLog = (orderId: number): Promise<string[]> => {
    return request.get(`/api/order-service/api/order/log/${orderId}`)
}

// ================= 后台 API (接口文档中没有找到，可能需要后端补充) =================

// 分页查询后台订单列表
export const getAdminOrderList = (params: PageRequest & { status?: string, userId?: number }): Promise<PageResponse<Order>> => {
    return request.get('/api/order-service/admin/order/list', { params })
}

// 更新订单状态
export const updateOrderStatus = (orderId: number, status: string): Promise<void> => {
    return request.post('/api/order-service/admin/order/status', { orderId, status })
}
